package org.ns.summer.mvc.dynamicexec;

import org.ns.summer.core.BeanUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Executable;
import java.util.Map;


public class ExecParamInfo {
	private Executable invokeObj; 
	private Map<Class<? extends Annotation>, Annotation> invokeAnns; 
	private Map<Class<? extends Annotation>, Annotation> paramAnns; 
	private Class<?> paramType; DynamicExecute autoParam; 
	private int paramIndex;
	private Annotation[] annotations;
	/** 参数加载信息
	 * 
	 * @param invokeObj 	可执行的这个对象, 例如 Method , Constructor
	 * @param invokeAnns		调用者拥有的注解
	 * @param paramAnns		当前参数拥有的注解
	 * @param paramType		参数类型
	 * @param autoParam	
	 * @param paramIndex	当前参数所处的index位置
	 * @return
	 */
	public ExecParamInfo(Executable invokeObj, Annotation[] annotations, Map<Class<? extends Annotation>, Annotation> invokeAnns,
			Map<Class<? extends Annotation>, Annotation> paramAnns, Class<?> paramType, DynamicExecute autoParam, int paramIndex) {
		super();
		this.invokeObj = invokeObj;
		this.annotations = annotations;
		this.invokeAnns = invokeAnns;
		this.paramAnns = paramAnns;
		this.paramType = paramType;
		this.autoParam = autoParam;
		this.paramIndex = paramIndex;
	}
	public Executable getInvokeObj() {
		return invokeObj;
	}
	public Map<Class<? extends Annotation>, Annotation> getInvokeAnns() {
		return invokeAnns;
	}
	public Map<Class<? extends Annotation>, Annotation> getParamAnns() {
		return paramAnns;
	}
	public Class<?> getParamType() {
		return paramType;
	}
	public DynamicExecute getAutoParam() {
		return autoParam;
	}
	public int getParamIndex() {
		return paramIndex;
	}
	/** 获得默认值
	 * 
	 * @return
	 */
	public Object getDefaultValue() {
		return getDefaultValue(null);
	}
	public Object getDefaultValue(Object def) {
		Object value = this.getAutoParam().get(paramType);
		if(value == null) {
			if(def != null) {
				value = def;
			}else {
				value = BeanUtils.getDefaultValue(paramType);
			}
		}
		return value;
	}

	public Annotation[] getAnnotations() {
		return annotations;
	}
}
